<?php
require('init.php');
//require(LIBWWWDIR . '/new_lib.php');

if( isset( $_POST['put']) OR isset( $_POST['able']) ){
//$conexion = connect();
//habilitar teams
if( isset( $_POST['able']) ){
	print_r($_POST['members']);
	/*$cat = $_POST['tc'];
	$table = tab_ins_contest( $cat );
	$query = "SELECT * FROM ".$table." WHERE answered= 0 ";
	$ins = mysql_query($query, $conexion) or die(mysql_error());
	$tam_res = mysql_num_rows($ins);
	$resultados = array();
	for($i = 0; $i < $tam_res; $i++){
		$datos = mysql_fetch_array($ins, MYSQL_BOTH);
		$resultados[$i] = $datos;
	}
	if( $cat == '1' OR  $cat == '2' OR $cat == '4' ){
	}
	//if($cat == '3'){
		$all_ok = array();
		/*foreach( $resultados as $row ){
			$login = generarLogin($row['2']);
	$teams = "INSERT INTO team (login, name, categoryid, authtoken, members, enable, member_static, 	row_const) values('$login', '".$row['2']."', '1', 'souling7', '".$row['3']."', '1','0', '0')";

			$res = mysql_query($teams, $conexion) or die(mysql_error());
			if($res){
				$all_ok[] = '1';
				//actualizar datos inscripciones
		$sql = @mysql_query("UPDATE ".$table."  SET answered= '1' WHERE username = '".$row[0]."' 
				AND cid = '".$row[1]."'");
			//echo "Se ha guardado con exito!!!!!!!!!!!<br>";
			}else{
				$all_ok[]  = '0' ;
			//echo "chanflee!! :S <br>";
			}
		}
		$ok = '0'; 
		$tam = count($all_ok);
		for( $i = 0; $i < $tam; $i++ ){
			if( $all_ok[$i] == '1' )
				$ok = $ok +1;
		}
		if( $ok == $tam ){
			echo '<script type="text/javascript" >'.
			'alert("Inscripción exitosa. MANDAR DATOS DE LOGEO A LOS TEAMS ");'.
			'</script>';
		}else{
			echo '<script type="text/javascript" >'.
			'alert("Error en la inscripcción ");'.
			'</script>';
		}*/
	//}*/
}
//armar teams
if( isset( $_POST['put']) ){
	$team_login = $_POST['team_select'];
	$members = $_POST['members'];
	$cid = $_POST['cid'];
	//$tab = tab_ins_contest($_POST['tc']);
	$tab = "ins_in_contest";
	//echo $team_login." ".$members." ".$cid." ".$tab;

	$teams = ( "UPDATE inner_team_members SET members='".$members."', cid='".$cid."' 
			WHERE login='".$team_login."'");
	$res = mysql_query($teams, $conn_db1) or die(mysql_error());
	if($res){
			$mem_list = array();
			$res_update = array();
			$mem_list[] = explode(",",$members);
			for( $i=0; $i<count($mem_list[0]); $i++ ){
				$res_update[$i] = update_ins_tabs($tab,$mem_list[$i],$cid);
			}
	}else{
				$all_ok[]  = '0' ;
			//echo "chanflee!! :S <br>";
	}
	$err = '1';
	for( $i=0; $i<count($res_update[0]); $i++ ){
			if( $res_update[$i] != '0')
				$err = $err AND '1';
			$err = $err AND '0';
	}
	if( $err == '0' )
		echo "errores en la actualización";
	echo "actualización ok";
	
}





	
}else{
	header('Location:index.php');
}




	


?>
